package com.whimscrew.video.controller;

import com.whimscrew.video.model.VideoDO;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("v1/video")
public class VideoController {



    @GetMapping("uploads/{userId}")
    public List<VideoDO> list(@PathVariable Long userId){
        Random random = new Random();
        int length = random.nextInt(10);
        List<VideoDO> resultList = new ArrayList<>(length);
        for(int i = 0;i <= length;i++ ){
            int titleLength = random.nextInt(20)+2;
            String title =  RandomStringUtils.random(titleLength  , 0x4e00, 0x9fa5, false, false);
            resultList.add(new VideoDO(userId,title, LocalDateTime.now()));
        }
        return resultList;
    }


    /**
     * 保存视频
     */
    @PostMapping
    public VideoDO save(@RequestBody VideoDO videoDO ){
        videoDO.setCreatetime(LocalDateTime.now());
        return videoDO;
    }

}
